package JUC;

import java.util.ArrayList;
import java.util.List;

/*  用Stream流式计算完成下面这道题（涉及到Stream流式计算，lambda表达式，函数式接口，链式编程）
 *  现在有5个用户，按要求筛选
 *  1 ID必须是偶数
 *  2 年龄必须大于23岁
 *  3 用户名转为大写字母
 *  4 用户名字母倒着排序
 *  5 只能输出一个用户
 * */
public class TestStream {
    public static void main(String[] args) {
        List<User> list = new ArrayList<>();
        list.add(new User(1,"jxc1",21));
        list.add(new User(2,"jxc2",24));
        list.add(new User(3,"jxc3",23));
        list.add(new User(4,"jxc6",27));
        list.add(new User(6,"jxc7",20));

        list.stream()
                .filter(user -> user.getId() % 2==0) //1 ID必须是偶数
                .filter(user -> user.getAge() > 23)
                .map(user -> user.getName().toUpperCase())
                .sorted((o1, o2) -> o2.compareTo(o1))
                .limit(1)
                .forEach(s -> System.out.println(s));
    }
}

class User{
    private int id;
    private String name;
    private int age;

    public User(int id, String name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}
